﻿<UserControl x:Class="ModernUILogViewer.Content.ContentSearchDate"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:mui="http://firstfloorsoftware.com/ModernUI"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"                
             xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"                
             xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
             xmlns:vm="clr-namespace:ModernUILogViewer.ViewModel"
             xmlns:conv="clr-namespace:ModernUILogViewer.Converters"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">

    <UserControl.Resources>
        <conv:DateFormatConverter x:Key="dateConverter" />
        <conv:DateListConverter x:Key="datelistConverter" />

        <DataTemplate x:Key="dateTimeStyle">
            <TextBlock Text="{Binding Converter={StaticResource dateConverter}, ConverterParameter='dd-MM-yyyy'}" />            
        </DataTemplate>        

    </UserControl.Resources>

    <StackPanel Margin="5, 10, 0, 0">
        <Grid HorizontalAlignment="Left">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="6*"></ColumnDefinition>
                <ColumnDefinition Width="4*"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>
            <TextBlock Text="START DATE" Style="{StaticResource Heading2}" Grid.Column="0" Grid.Row="0" />
            <ComboBox x:Name="sdtCmb" ItemsSource="{Binding StartDateList, Converter={StaticResource datelistConverter}}" SelectedItem="{Binding StartDate}" Grid.Column="0" Grid.Row="1" Margin="{StaticResource DefaultTopMargin}" ></ComboBox>
            <TextBlock HorizontalAlignment="Center" Text="TIME" Style="{StaticResource Heading2}" Grid.Column="1" Grid.Row="0" Margin="{StaticResource DefaultLeftMargin}"  />
            <xctk:DateTimeUpDown x:Name="startTime" Grid.Column="1" Grid.Row="1" Format="ShortTime" Value="{Binding StartDate, Mode=TwoWay}" Margin="{StaticResource DefaultTopLeftMargin}"  />

            <TextBlock Text="END DATE" Style="{StaticResource Heading2}" Grid.Column="0" Grid.Row="2" Margin="{StaticResource DefaultTopMargin}" />
            <TextBlock HorizontalAlignment="Center" Text="TIME" Style="{StaticResource Heading2}"  Margin="{StaticResource DefaultTopLeftMargin}" Grid.Column="1" Grid.Row="2"  />
            <ComboBox x:Name="edtCmb" ItemsSource="{Binding EndDateList, Converter={StaticResource datelistConverter}}" SelectedItem="{Binding EndDate}" Grid.Column="0" Grid.Row="3" Margin="{StaticResource DefaultTopMargin}" ></ComboBox>
            <xctk:DateTimeUpDown x:Name="endTime" Grid.Column="1" Grid.Row="3" Format="ShortTime" Value="{Binding EndDate, Mode=TwoWay}" Margin="{StaticResource DefaultTopLeftMargin}" />
            <Button Content="Filter" Margin="{StaticResource DefaultTopMargin}" Command="{Binding FilterLogEntries}" Width="80" Grid.Row="4" />                
            <Button Content="Clear" Margin="{StaticResource DefaultTopLeftMargin}" Width="80" x:Name="clearButton" Grid.Row="4" Grid.Column="1" />
        </Grid>
    </StackPanel>

    <i:Interaction.Triggers>

        <i:EventTrigger EventName="Click" SourceObject="{Binding ElementName=clearButton}">
            <ei:ChangePropertyAction TargetObject="{Binding ElementName=sdtCmb}" PropertyName="SelectedIndex" Value="0" />
            <ei:ChangePropertyAction TargetObject="{Binding ElementName=edtCmb}" PropertyName="SelectedIndex" Value="0" />
            <i:InvokeCommandAction Command="{Binding FilterLogEntries}" />
        </i:EventTrigger>
        <ei:PropertyChangedTrigger Binding="{Binding StartDate}">
            <i:InvokeCommandAction Command="{Binding RefreshLastDateList}" />
        </ei:PropertyChangedTrigger>

        <!--<ei:DataTrigger Binding="{Binding ElementName=sdtCmb, Path=SelectedIndex}" Value="0">
            <ei:ChangePropertyAction TargetObject="{Binding ElementName=startTime}" PropertyName="IsEnabled" Value="False" />
        </ei:DataTrigger>
        <ei:DataTrigger Binding="{Binding ElementName=sdtCmb, Path=SelectedIndex}" Value="0" Comparison="NotEqual">
            <ei:ChangePropertyAction TargetObject="{Binding ElementName=startTime}" PropertyName="IsEnabled" Value="True" />
        </ei:DataTrigger>

        <ei:DataTrigger Binding="{Binding ElementName=edtCmb, Path=SelectedIndex}" Value="0">
            <ei:ChangePropertyAction TargetObject="{Binding ElementName=endTime}" PropertyName="IsEnabled" Value="False" />
        </ei:DataTrigger>
        <ei:DataTrigger Binding="{Binding ElementName=edtCmb, Path=SelectedIndex}" Value="0" Comparison="NotEqual">
            <ei:ChangePropertyAction TargetObject="{Binding ElementName=endTime}" PropertyName="IsEnabled" Value="True" />
        </ei:DataTrigger>-->

    </i:Interaction.Triggers>


</UserControl>
